package supershop.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import supershop.dao.IOrderDetailDao;
import supershop.dao.IOrdersDao;
import supershop.dao.IUsersDao;
import supershop.model.OrderDetail;
import supershop.model.Orders;

@Controller
@RequestMapping("/mall/html/orders")
public class MallOrdersController {
	@Resource
	private IOrdersDao ordersDao;
	@Resource
	private IOrderDetailDao orderDetailDao;
	@Resource
	private IUsersDao usersDao;
	
	//添加订单
	@RequestMapping("/addOrder.do")
	@ResponseBody
	public int addOrder(Orders o) {
		//将用户默认地址设为订单收获地址
		int addressId = usersDao.findAddressId(o.getUserId());
		o.setAddressId(addressId);
		ordersDao.addOrder(o);//返回的主键已经回传到请求参数的id属性中
		return o.getId();
	}
	
	//添加订单详情
	@RequestMapping("/addOrderDetail.do")
	@ResponseBody
	public int addOrderDetail(OrderDetail od) {
		return orderDetailDao.addDetail(od);
	}
}
